define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'hospital/hospital/index' + location.search,
                    add_url: 'hospital/hospital/add',
                    edit_url: 'hospital/hospital/edit',
                    del_url: 'hospital/hospital/del',
                    multi_url: 'hospital/hospital/multi',
                    import_url: 'hospital/hospital/import',
                    file_url:'hospital/hospitaltime/index',
                    table: 'hospital',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                //fixedColumns: true,
                //fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'hospital_name', title: __('Hospital_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'hospital_images', title: __('Hospital_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                       // {field: 'hospital_content', title: __('Hospital_content')operate: 'LIKE',},
                      //  {field: 'province_id', title: __('Province_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'province', title: __('Province'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'city_id', title: __('City_id')},
                        {field: 'city', title: __('City'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                       // {field: 'area_id', title: __('Area_id')},
                        {field: 'area', title: __('Area'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'lng', title: __('Lng'), operate: 'LIKE'},
                      //  {field: 'lat', title: __('Lat'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons:[  {
                                name: 'file',
                                text: __('预约时间段'),
                                title: __('预约时间段'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-step',
                                url: function (row) {
                                    return $.fn.bootstrapTable.defaults.extend.file_url+"?hospital_id="+row.id
                                }
                            },
                            ]
                        }
                    ]
                ]
            });

            $('.btn-updatetags').on('click',function(){
                var ids = Table.api.selectedids(table);
                ids = ids.join(',');
                console.log(ids);
                //Form.api.bindevent($("form[role=form]"));
                //     location.href = Fast.api.fixurl('service/service_log/batch_download/ids/'+ids);
                var that = this;
                var element=that;
                var data = element ? $(element).data() : {};
                var action="updatetags";
                var params = typeof data.params !== "undefined" ? (typeof data.params == 'object' ? $.param(data.params) : data.params) : '';

                var url='hospital/hospital/updatetags?ids='+ids;
                Fast.api.open(url,__('批量修改服务类型'),{
                    callback:function(ret){
                        //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
                        console.log(ret);
                        if(ret.code==1){

                            layer.msg('修改成功');
                            window.location.reload();





                        }

                    },
                });
                return false;


            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        updatetags:function (){
            Form.api.bindevent($("form[role=form]"), function(data, ret){
                //给表单绑定新的回调函数 接收 控制器 success(msg,url,data)或者error(msg,url,data)
                Fast.api.close(ret);//在这里

            }, function(data, ret){
                console.error("错误");
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
